package com.admin.service.security.impl;

import com.admin.service.SysUserService;
import com.admin.service.security.vo.CustomerUserDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.Objects;


public class CustomerUserDetailsService implements UserDetailsService {

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if (!Objects.equals("lee", username)) {
            throw new UsernameNotFoundException(username);
        }
        String pwd = "123456";//"{noop}123456"
        pwd = passwordEncoder.encode(pwd);
        //文本保存方式
        UserDetails userDetails = new CustomerUserDetails(username, pwd);
        return userDetails;
    }
}
